package onion.molingo2o.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import onion.molingo2o.Config;
import onion.molingo2o.R;

/**
 * Created by Administrator on 2015/3/13.
 */
public class ImageAdapter extends BaseAdapter {
    private Context context;
    private List<String> images;
  private AbsListView.LayoutParams params;
    public ImageAdapter(Context context, List<String> images) {
        this.context = context;
        this.images = images;
        params=new AbsListView.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,context.getResources().getDimensionPixelSize(R.dimen.item_life_photo));
    }

    @Override
    public int getCount() {
        return images.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView=View.inflate(context, R.layout.img_active,null);
            convertView.setLayoutParams(params);
//            ((ImageView)convertView).setScaleType(ImageView.ScaleType.CENTER_CROP);
        }

        ImageLoader.getInstance().displayImage(images.get(position),(ImageView)convertView, Config.circleIconDefault);
        return convertView;
    }

    @Override
    public Object getItem(int position) {
        return images.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

}
